<?php
set_time_limit(120);
if (defined('debug')){error_reporting(E_ERROR | E_PARSE);}
require_once 'config.php';
require_once 'function.php';

$tasklist = array();
$tasklist = include 'tasklist.php';
$n = count($tasklist);

echo "抓取开始，共有{$n}个抓取任务<br/>";
echo "--------------------<br/>\n";
foreach ($tasklist as $task)
{
    echo "正在抓取{$task['url']}<br/>";
    $result = execTask($task);
    echo "输出目录 {$task['save_dir']}<br/>";
        switch ($result['err']) {
            case FETCH_SUCCESS:
                echo '抓取并保存成功<br/>';
                echo "保存文件名 {$result['filename']}<br/>\n";
                break;
            case FETCH_NOT_MODIFIED:
                echo '目标文件未修改，无需保存';
                break;
            case FETCH_FAILED:
                echo '抓取失败';
                break; 
            case FETCH_NOT_SUPPORT:
                echo '暂不支持的方法';
                break;     
            default:
                echo '未知错误';
                break;
        }
    echo "<br/>\n";
    echo "--------------------<br/>\n";
}
echo "抓取完毕\n";
?>